package com.ruoyi.web.controller.comlbs;


import java.util.Arrays;
import java.util.List;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.domain.LatLng;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.request.electricFence.PoiCitySearchParam;
import com.ruoyi.system.service.CommonService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ElectricFence;
import com.ruoyi.system.service.IElectricFenceService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电子围栏Controller
 * 
 * @author wp
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/comlbs/electricFence")
public class ElectricFenceController extends BaseController {
    @Autowired
    private IElectricFenceService electricFenceService;
    @Autowired
    private CommonService commonService;

    /**
     * 查询电子围栏列表
     */
    @ApiOperation("电子围栏列表")
    @ApiOperationSupport(includeParameters = {"name","type","companyId"})
    @GetMapping("/list")
    public TableDataInfo list(ElectricFence electricFence) {
        startPage();
        List<ElectricFence> list = electricFenceService.selectList(electricFence);
        return getDataTable(list);
    }

    /**
     * 查询电子围栏列表
     */
    @ApiOperation("查询电子围栏列表(不分页)")
    @ApiOperationSupport(includeParameters = {"name","type","companyId"})
    @GetMapping("/listAll")
    public AjaxResult listAll(ElectricFence electricFence) {
        return success(electricFenceService.selectList(electricFence));
    }

    /**
     * 获取电子围栏详细信息
     */
    @ApiOperation("获取电子围栏详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(electricFenceService.getById(id));
    }

    /**
     * 新增电子围栏
     */
    @ApiOperation("新增电子围栏")
    @ApiOperationSupport(includeParameters = {"companyId","name","type","address","xyWgs84","xyGcj02"})
    @Log(title = "电子围栏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElectricFence electricFence) {
        electricFence.setId(null);
        return toAjax(electricFenceService.saveOrUpdateElectricFence(electricFence));
    }

    @ApiOperation("编辑电子围栏")
    @ApiOperationSupport(includeParameters = {"id","companyId","name","type","address","xyWgs84","xyGcj02"})
    @Log(title = "电子围栏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElectricFence electricFence) {
        if (electricFence.getId() == null) throw new ServiceException("ID不能为空");
        return toAjax(electricFenceService.saveOrUpdateElectricFence(electricFence));
    }

    /**
     * 删除电子围栏
     */
    @ApiOperation("删除电子围栏")
    @Log(title = "电子围栏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(electricFenceService.removeByIds(Arrays.asList(ids)));
    }


}
